-- function mirror >= 2.5.4
-- xmake test >= 2.8.5
set_xmakever("2.8.5")

add_rules("plugin.compile_commands.autoupdate", {outputdir = ".vscode"})

add_rules("mode.debug", "mode.release")
set_languages("c17", "c++17")
set_warnings("all")

add_requires("gtest")
add_requires("boost")
add_requires("openmp")
add_requires("benchmark")
-- tcmalloc for benchmark
-- TODO: if `add_requires` can be added in option
-- TODO: `add_packages` can't be in option
-- TODO: Does the option default reflect defines correctly in compile_commands.json
add_requires("gperftools", {configs = {tcmalloc = true}})

add_includedirs("inc")
add_includedirs("tests/inc")

target("p1003")
    set_kind("binary")
    add_files("src/p1003.cpp")

target("p1067")
    set_kind("binary")
    add_files("src/p1067.cpp")
    
target("p1540")
    set_kind("binary")
    add_files("src/p1540.cpp")
        
target("div3-977a")
    set_kind("binary")
    add_files("src/div3-977a.cpp")
        
target("div3-977b")
    set_kind("binary")
    add_files("src/div3-977b.cpp")

target("div3-977c")
    set_kind("binary")
    add_files("src/div3-977c.cpp")

target("div3-977d")
    set_kind("binary")
    add_files("src/div3-977d.cpp")

target("pat-a1")
    set_kind("binary")
    add_files("src/pat-a1.cpp")

target("pat-a2")
    set_kind("binary")
    add_files("src/pat-a2.cpp")

target("pat-a3")
    set_kind("binary")
    add_files("src/pat-a3.cpp")

target("pat-a4")
    set_kind("binary")
    add_files("src/pat-a4.cpp")

target("par-odd-even-sort")
    set_kind("binary")
    add_files("src/par-odd-even-sort.cpp")
    add_packages("openmp")

target("par-merge-sort")
    set_kind("binary")
    add_files("src/par-merge-sort.cpp")
    add_packages("openmp")

target("par-hello")
    set_kind("binary")
    add_files("src/par-hello.cpp")
    add_packages("openmp")

target("cpp-char")
    set_kind("binary")
    add_files("src/cpp-char.cpp")

target("stl_datastruct")
    set_kind("binary")
    add_files("src/stl_datastruct.cpp")

target("lru_debug")
    set_kind("binary")
    add_files("src/lru_debug.cpp")

-- gtest

-- SEE: https://xmake.io/#/zh-cn/manual/project_target?id=targetadd_tests
for _, file in ipairs(os.files("tests/*_test.cpp")) do
    local name = path.basename(file)
    target(name)
        set_kind("binary")
        set_default(false)
        add_files("tests/" .. name .. ".cpp")
        add_packages("gtest")
        -- set test group 'noargs'
        add_tests("noargs")
end

-- google benchmark

for _, file in ipairs(os.files("tests/bench/*_bench.cpp")) do
    local name = path.basename(file)
    target(name)
        set_kind("binary")
        add_files("tests/bench/" .. name .. ".cpp")
        add_packages("benchmark", "gperftools")
end